import React from 'react';
import {Link} from "react-router-dom";
import GUtils from "@/utils";

const renderAmount = (vo, field)=>{
    let v1 = vo[field+"AmountBefore"]||0;
    let v2 = vo[field+"AmountAfter"]||0;
    console.log(vo.id, vo,field, v1,v2, vo.withdrawableAmountBefore)
    if(v1==v2){
        return <div className="amount-nochange">{v1.toFixed(2)}</div>
    }
    return <div className={v1>v2 ? "amount-sub" : "amount-add"}>{v1.toFixed(2)} -> {v2.toFixed(2)}</div>
}
const Config = (Action) => {
    const Handlers = {
        enabled({id, enabled, name}) {
            enabled = !enabled;
            let op = enabled ? "启用" : "禁用";
            GUtils.confirm(op, `确认${op}门店 [${name}] 吗?`, () => {
                Action.enabled(id, enabled);
            });
        }
    }
    const columns = [
        {title: "事件", dataIndex: "eventType", width: 120, render(v,vo){
            return <div>
                <div className="text-center">{GUtils.dealEnumValue(v, "ShopBalanceEvent")}</div>
                <div className="fs-12">{GUtils.dateTimeFormatter(vo.createTime)}</div>
            </div>
            }},

        {title: "门店", dataIndex: "shopName", width: 140},
        {
            title: "类别", dataIndex: "referenceType", width: 160, render(v, vo) {
                let isWash = v == 2;
                return <div>
                    <div>类别：{GUtils.dealEnumValue(v, "ShopBalanceReferenceType")}</div>
                    <div>单号：{vo.referenceNumber}</div>
                    {
                        isWash
                            ? <div>
                                <div>订单金额：{vo.orderAmount.toFixed(2)}</div>
                                <div>折扣：{vo.discount.toFixed(2)}</div>
                            </div>
                            : <div>提现金额：{vo.orderAmount.toFixed(2)}</div>
                    }

                </div>
            }
        },

        {title: "金额变化", dataIndex: "amount", width: 60, render:v=>{
            return <div className="text-center">{Math.abs(v).toFixed(2)}</div>
            //return <div className={v<0?"amount-sub":"text-center"}>{v.toFixed(2)}</div>
        }},

        {title: "冻结金额", dataIndex: "frozen", width: 120, render:(v,vo)=>renderAmount(vo, "frozen")},
        {title: "累计提现金额", dataIndex: "totalWithdrawal", width: 120, render:(v,vo)=>renderAmount(vo, "totalWithdrawal")},
        {title: "可提现金额", dataIndex: "withdrawable", width: 120, render:(v,vo)=>renderAmount(vo, "withdrawable")},
        {title: "提现中金额", dataIndex: "withdrawing", width: 120, render:(v,vo)=>renderAmount(vo, "withdrawing")},

    ];
    return {
        ...window.CONFIG.getPagerConfig(Action), columns
    };
};


export default Config;
